//给定一个头节点为 head 的链表用于记录一系列核心肌群训练项目编号，请查找并返回倒数第 cnt 个训练项目编号。 
//
// 
//
// 示例 1： 
//
// 
//输入：head = [2,4,7,8], cnt = 1
//输出：8 
//
// 
//
// 提示： 
//
// 
// 1 <= head.length <= 100 
// 0 <= head[i] <= 100 
// 1 <= cnt <= head.length 
// 
//
// 
//
// Related Topics 链表 双指针 👍 512 👎 0

package leetcode.editor.cn;
//java:训练计划 II
public class QLCR140LianBiaoZhongDaoShuDiKgeJieDianLcof {
    public static void main(String[] args){
        Solution solution = new QLCR140LianBiaoZhongDaoShuDiKgeJieDianLcof().new Solution();
    }
    //leetcode submit region begin(Prohibit modification and deletion)
/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode() {}
 *     ListNode(int val) { this.val = val; }
 *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 * }
 */
class Solution {
    public ListNode trainingPlan(ListNode head, int cnt) {
        if (head == null) return null;
        ListNode leftNode = head, rightNode = head;
        for (int i = 0; i < cnt; i++) {
            rightNode = leftNode.next;
        }
        while (rightNode != null) {
            rightNode = rightNode.next;
            leftNode = leftNode.next;
        }
        return leftNode;
    }
}
//leetcode submit region end(Prohibit modification and deletion)

}